package com.andy.nature.utils

import android.app.Activity
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.andy.toast.extend.showNormalToast
import com.sch.share.WXShareMultiImageHelper
import java.io.FileInputStream
import java.text.SimpleDateFormat


/**
 * Author:Andy
 * Date:2023/4/27 19:29
 * Description:ShareUtils
 */
object ShareUtils {

    fun shareToWechatCircle(activity: Activity, title: String, filePathList: List<String>) {
        val list = ArrayList<Bitmap>()
        val count = filePathList.size
        for (i in 0 until count) {
            val fis = FileInputStream(filePathList[i])
            val bitmap = BitmapFactory.decodeStream(fis)
            list.add(bitmap)
        }
        // 分享图片和文字，并设置本次分享是否自动发布
        val options = com.sch.share.Options().apply {
            text = title
            isAutoFill = true
            isAutoPost = true
            needShowLoading = true
            onPrepareOpenWXListener = {
                "打开微信回调".showNormalToast()
            }
        }
        val array = list.toTypedArray()
        WXShareMultiImageHelper.shareToTimeline(activity, array, options)
    }

    fun shareToWechatFriends(activity: Activity, filePathList: List<String>) {
        val list = ArrayList<Bitmap>()
        val count = filePathList.size
        for (i in 0 until count) {
            val fis = FileInputStream(filePathList[i])
            val bitmap = BitmapFactory.decodeStream(fis)
            list.add(bitmap)
        }
        val array = list.toTypedArray()
        WXShareMultiImageHelper.shareToSession(activity, array)
    }

    /*
     * 将时间转换为时间戳
     */
    fun dateToStamp(s: String?): Long {
        val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        val date = simpleDateFormat.parse(s)
        return date.time
    }
}
